from django.core.mail import send_mail
import random
import string


def SendCaptcha(email):
    '''
    随机验证码生成并发送
    '''
    captcha = ''.join(random.sample(string.ascii_letters + string.digits, 6))

    # 邮件内容
    subject = '验证码'
    message = f'您的验证码是：{captcha}'
    from_email = 'dreamlife2024@163.com'

    send_mail(subject, message, from_email, [email])

    return captcha
